package com.z.demo

import org.apache.flink.table.api._

/**
 * @Author wenz.ma
 * @Date 2021/10/26 13:54
 * @Desc sql 中 group by 的使用
 */
object SqlGroupBy01 {
  def main(args: Array[String]): Unit = {
    val settings = EnvironmentSettings.newInstance().inStreamingMode().build()
    val tEnv = TableEnvironment.create(settings)
    tEnv.executeSql(
      """
        |create table student1 (
        |id int ,
        |name string
        |)with(
        | 'connector' = 'kafka',
        |  'topic' = 'test-topic',
        |  'properties.bootstrap.servers' = 'server120:9092',
        |  'properties.group.id' = 'testGroup',
        |  'scan.startup.mode' = 'latest-offset',
        |  'format' = 'csv'
        |)
        |""".stripMargin)
    //选择多个列查询
    //std.select('id, 'name).execute().print()
    //根据sql查询结果
    tEnv.executeSql(
      """
        |select id,name,count(1)cnt
        |from
        |student1
        |group by id,name
        |""".stripMargin)
      .print()
  }
}
